<template>
  <div>
    <el-dialog
      title="添加学生"
      :visible="dialogAddVisible"
      @update:visible="setDialogAddVisible"
      width="30%"
    >
      <el-form label-width="80px">
        <el-form-item label="学生姓名:">
          <el-input v-model="stuName"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="setDialogAddVisible(false)">取 消</el-button>
        <el-button type="primary" @click="add()">添 加</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { saveStu } from "../service/index";
import { mapActions, mapMutations, mapState } from "vuex";
export default {
  data() {
    return {
      stuName: "",
    };
  },
  computed: {
    ...mapState("student", ["dialogAddVisible"]),
  },
  methods: {
    async add() {
      let { stuName } = this;
      console.log(stuName);
      let result = await saveStu(stuName);
      this.stuName = "";
      this.showStu();
      this.setDialogAddVisible(false);
    },

    ...mapMutations("student", ["setDialogAddVisible"]),
    ...mapActions("student", ["showStu"]),
  },
};
</script>

<style></style>
